package bookmanage;

import java.util.Scanner;

public class Main {
    // 编写代码的主题逻辑
    public static void main(String[] args) {
         User user = login();
         while (true){
             int choice = user.menu();
             user.doOperation(choice);
         }
    }

    private static User login() {
        // 实现用户登录逻辑
        // 1. 用户输入用户名和密码
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.next();
        System.out.println("请输入密码：");
        String password = scanner.next();
        // 2. 从数据库根据用户名来查找密码
        UserDao userDao = new UserDao();
        User user = userDao.selectByName(username);
        if (user == null){
            //用户不存在
            System.out.println("该用户不存在！登录失败！");
            System.exit(0);
        }
        if (!user.getPassword().equals(password)){
            //密码不正确
            System.out.println("密码错误！登录失败！");
            System.exit(0);
        }
        return user;
    }
}
